package com.tqyan.start.controller;

import com.tqyan.model.Result;
import com.tqyan.model.controller.request.DataShadowRequest;
import com.tqyan.service.service.DataShadowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description 数字缩影API
 * <p> <功能详细描述> </p>
 *
 * @author 陈晨
 * @date 2023/4/11 17:20
 */
@RestController
@RequestMapping("/dataShadow/")
@Slf4j
//@Api(tags = "数字缩影API")
public class DataShadowController {

    @Autowired
    private DataShadowService dataShadowService;

    @PostMapping("/set")
//    @ApiOperation(value = "设置角色")
    public Result<Void> set(@RequestBody DataShadowRequest request) {
        try {
            dataShadowService.set(request);
            return Result.success();
        } catch (Exception e) {
            log.error("[数字缩影] request={}, 设置数字缩影, 异常: {}"
                    , request, e.getMessage(), e);
            return Result.fail(e.getMessage());
        }
    }

    @PostMapping("/queryByName")
//    @ApiOperation(value = "查询角色描述")
    public Result<String> queryByUser(@RequestBody DataShadowRequest request) {
        if (null == request) {
            return Result.fail("请求参数不可为空");
        }
        try {
            return Result.success(dataShadowService.queryDescription(request.getName()));
        } catch (Exception e) {
            log.error("[数字缩影] request={}, 查询用户数字缩影, 异常: {}"
                    , request, e.getMessage(), e);
            return Result.fail(e.getMessage());
        }
    }

}


